/*
 * @lc app=leetcode.cn id=75 lang=typescript
 *
 * [75] 颜色分类
 */

// @lc code=start
/**
 Do not return anything, modify nums in-place instead.
 */
function sortColors(nums: number[]): void {
    const map = new Map();
    map.set(0, 0)
    map.set(1, 0)
    map.set(2, 0)
    for (let i = 0; i < nums.length; i++) {
        const len = map.get(nums[i]);
        map.set(nums[i], len ? len + 1 : 1);
    }
    let index = 0;
    for (let [k, v] of map) {
        let x = 0;
        while (x < v) {
            nums[index] = k;
            x++;
            index++;
        }
    }
};

// sortColors([2, 0, 2, 1, 1, 0]);
// @lc code=end

